package com.daxt.service.impl;


import javax.servlet.http.HttpServletRequest;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.daxt.mapper.sys.DeptMapper;
import com.daxt.model.service.base.vo.Dept;
import com.daxt.model.service.base.vo.UserDept;
import com.daxt.utils.IpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.daxt.base.common.util.RedisUtil;
import com.daxt.base.common.util.UserInfoUtil;
import com.daxt.mapper.sys.OperationLogMapper;
import com.daxt.model.service.base.result.UserInfo;
import com.daxt.model.service.base.vo.OperationLog;
import com.daxt.service.OperationLogService;


@Service
public class OperationLogServiceImpl implements OperationLogService {
	@Autowired
	private OperationLogMapper operationLogMapper;
	@Autowired
	private RedisUtil redisUtil;
	@Autowired
	private UserInfoUtil userInfoUtil;
	//@Autowired
	//private DeptMapper deptMapper;

	@Override
	public void saveLog(String type,String text, HttpServletRequest request) {
		UserInfo loginInfo = userInfoUtil.getLoginInfo(UserInfo.class, redisUtil, request);

		if(loginInfo!=null) {
			String ip= IpUtil.getIP(request);
			//QueryWrapper<Dept> queryWrapper=new QueryWrapper();

			//System.out.println("loginInfo.getDeptId():"+loginInfo.getDeptId());


			//queryWrapper.eq("id",loginInfo.getDeptId());
			//Dept dept= deptMapper.selectOne(queryWrapper);
			//String deptName="";
			String fondsId=loginInfo.getFondsId();
			OperationLog entity = OperationLog.buildParam(type,text,null,loginInfo.getRealName(),ip,loginInfo.getDeptName(),fondsId);
			operationLogMapper.insert(entity);
		}
	}
	@Override
	public void saveLog(String type,String text, UserInfo loginUser ,String ip) {

		//String deptName=null;
		String fondsId=loginUser.getFondsId();
		OperationLog entity = OperationLog.buildParam(type,text,null,loginUser.getRealName(),ip,loginUser.getDeptName(),fondsId);
		operationLogMapper.insert(entity);
	}

	@Override
	public void saveLog(String type,String text,String param, HttpServletRequest request) {
		UserInfo loginInfo = userInfoUtil.getLoginInfo(UserInfo.class, redisUtil, request);
		//System.out.println("333333333333333:"+loginInfo);
		if(loginInfo!=null) {
			String ip= IpUtil.getIP(request);
			//String deptName=null;
			String fondsId=loginInfo.getFondsId();
			OperationLog entity = OperationLog.buildParam(type,text,param,loginInfo.getRealName(),ip,loginInfo.getDeptName(),fondsId);
			operationLogMapper.insert(entity);
		}
	}



	

	
}
